import java.util.Arrays;

public class ArrDemo {

    public static void f1(){
        int[] arr= {1,2,3,4,5,6,7,8,9};

        for (int i = 0,j = arr.length-1;i < arr.length/2; i++,j--) {
            int num = arr[i];
            arr[i] = arr[j];
            arr[j] = num;
        }
        System.out.println(arr[0]);
    }

    public static void f2(){
        int[] arr= {9,4,6,-29,7};
        for (int k = 0; k <arr.length-1 ; k++) {
            for (int i = 0, j = i + 1; i < arr.length - 1; i++, j++) {
                if (arr[i] > arr[j]) {
                    int num = arr[i];
                    arr[i] = arr[j];
                    arr[j] = num;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }

    public static void f3(){
        int[] arr= {1,4,8,3,5,-2,-38};
        boolean flag = false;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if (arr[i]>arr[j]){
                    int num = arr[i];
                    arr[i] = arr[j];
                    arr[j] = num;
                    flag = true;
                }
            }
            if (!flag){break;}
        }
        System.out.println(Arrays.toString(arr));
    }

    public static void main(String[] args) {
        f1();
        f2();
        f3();
    }
}
